#ifndef SERIALPORTSMANAGER_H
#define SERIALPORTSMANAGER_H


#include <QMainWindow>
#include <QMutex>
#include <QSerialPort>
#include <QWaitCondition>


namespace Ui {
class SerialPortsManager;
}

class SerialPortsManager: public QObject
{
    Q_OBJECT

public:
    explicit SerialPortsManager( QMainWindow *mainwidow);
    int loadConfigs();

    QMainWindow *mainwidow;

    QSerialPort *serialPort;                                 //声明串口类

    int baudRateInt;
    QSerialPort::DataBits dataBits;
    QSerialPort::Parity parity;
    QSerialPort::StopBits stopBits;
    QSerialPort::FlowControl flowControl;


    int configCOM();

    int openCOM(QString portName);
    int closeCOM();

    int sendCOM(QSerialPort *com, const char *data);
    int sendCOM( const char *data);

    QMutex mutex;
    QWaitCondition waitCon;
    QByteArray newReceived;

    bool waitCondition(unsigned long time);
    bool waitForReceive(int time);

    void setWaitCon(const QWaitCondition &value);

public slots:

  //  void receiveCOM();//串口数据读取显示

signals:

    void someSignal(const QString &);

private:


};

#endif // SERIALPORTSMANAGER_H
